home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 32 / Amiga Format AFCD32 (Nov 1998, Issue 117).iso / -seriously_amiga- / programming / other / simpleaudio / simpleaudio.i < prev    next >
Text File  |  1998-08-24  |  3KB  |  218 lines

  1. * SimpleAudio.i
  2. *
  3. * © 1998 Blasio Muscat
  4. *
  5.  
  6.     incdir    "include:"
  7.  
  8.     IFND    exec_exec_lib.i
  9.     include    exec/exec_lib.i
  10.     ENDC
  11.  
  12.     IFND    exec_exec.i
  13.     include    exec/exec.i
  14.     ENDC
  15.  
  16.     IFND    exec_ports.i
  17.     include    exec/ports.i
  18.     ENDC
  19.  
  20.     IFND    exec_initializers.i
  21.     include    exec/initializers.i
  22.     ENDC
  23.  
  24.     IFND    exec_nodes.i
  25.     include    exec/nodes.i
  26.     ENDC
  27.  
  28.     IFND    exec_io.i
  29.     include    exec/io.i
  30.     ENDC
  31.  
  32.     IFND    devices_audio.i
  33.     include    devices/audio.i
  34.     ENDC
  35.  
  36.  
  37.  
  38.     Bra.w    End_SimpleAudio
  39.  
  40. UNSTOPPABLE  equ    127
  41. EMERGENCIES  equ     95
  42. ATTENTION    equ     85
  43. SPEECH       equ     75
  44. INFORMATION  equ     60
  45. MUSIC        equ      0
  46. EFFECT       equ    -35
  47. BACKGROUND   equ    -90
  48. SILENCE      equ -128
  49.  
  50.  
  51. NTSC_CLOCK    equ    3579545 * American Amigas - 60Hz
  52. PAL_CLOCK     equ    3546895 * European Amigas - 50Hz 
  53.  
  54. CLOCK = PAL_CLOCK    ; Change according to where you are located
  55.  
  56.  
  57. ; ********* Flags
  58.  
  59. LEFT1    EQU    $1
  60. RIGHT1    EQU    $2
  61. RIGHT2    EQU    $4
  62. LEFT2    EQU    $8
  63.  
  64. PERIOD    EQU    $10
  65. WAIT    EQU    $20
  66.  
  67.  
  68.  
  69. ALLOCAUDIO    MACRO    
  70.     movem.l    d2-d7/a0-a6,-(a7)
  71.     move.l    \1,d0            ; Channel (L1/L2/R1/R2)
  72.     move.l    \2,d1            ; Pri      (MUSIC/FX/EMERGENCY)
  73.     jsr    AllocAudio
  74.     movem.l    (a7)+,d2-d7/a0-a6
  75.     ENDM
  76.  
  77. PLAY    MACRO
  78.     movem.l    d1-d7/a0-a6,-(a7)
  79.     move.l    \1,a0            ; Pointer to Sample
  80.     move.l    \2,d0            ; Lenght of Sample
  81.     move.l    \3,d1            ; Frequency / Period
  82.     move.l    \4,d2            ; Volume
  83.     move.l    \5,d3            ; Channel + Period/Freq (Flags)
  84.     move.l    \6,d4            ; No of Times to Play
  85.     jsr    Play
  86.     movem.l    (a7)+,d1-d7/a0-a6
  87.     ENDM
  88.  
  89. DEALLOCAUDIO    MACRO
  90.     movem.l    d0-d7/a0-a6,-(a7)
  91.     jsr    DeAllocAudio
  92.     movem.l    (a7)+,d0-d7/a0-a6
  93.     ENDM
  94.  
  95.  
  96.  
  97.  
  98. AllocAudio:
  99. ; d0 Channels
  100. ; d1 Priority
  101.  
  102.     lea    AuReq,a1
  103.     move.b    d1,LN_PRI(a1)
  104.     move.b    d0,AuChannels
  105.  
  106.     move.l    4.w,a6
  107.     jsr    _LVOCreateMsgPort(a6)
  108.     move.l    d0,_AuReplyPort
  109.  
  110.     lea    AuReq,a1
  111.     move.l    _AuReplyPort,MN_REPLYPORT(a1)
  112.  
  113.     clr.w    ioa_AllocKey(a1)
  114.     move.l    #AuChannels,ioa_Data(a1)
  115.     move.l    #1,ioa_Length(a1)
  116.  
  117.     move.l    #AuDevice,a0
  118.     clr.l    d0
  119.     clr.l    d1
  120.     move.l    4.w,a6
  121.     jsr    _LVOOpenDevice(a6)
  122.  
  123.     move.l    #AuReq,a1
  124.     move.l    IO_UNIT(a1),AuUnit
  125.  
  126. ; Returns 0 if OK or else an error code
  127.  
  128.     rts
  129.  
  130.  
  131. Play:
  132. ; a0    pointer to sample
  133. ; d0    lenght of sample (will be turned into even if necessary)
  134. ; d1    Frequency or Period
  135. ; d2    Volume
  136. ; d3    Flags (Select Channel, Freq/Period, Wait/DONOTWAIT)
  137. ; d4    No of times to play
  138.  
  139. ; This routine only accepts 1 Sample at a time.
  140.  
  141.     lea    AuReq,a1
  142.     move.b    #ADIOF_PERVOL,IO_FLAGS(a1)
  143.     move.l    a0,ioa_Data(a1)
  144.     bclr.l    #0,d0        ; if it is odd make it even
  145.     move.l    d0,ioa_Length(a1)
  146.     
  147.     move.l    d3,d7    ; Copy of Flags
  148.     andi.l    #PERIOD,d7
  149.     tst.l    d7
  150.     bne    Period_Play
  151.  
  152.     move.l    #CLOCK,d6
  153.     divs    d1,d6
  154.     
  155.     
  156.     move.l    d6,d1
  157. Period_Play    move.w    d1,ioa_Period(a1)
  158.     move.w    d2,ioa_Volume(a1)
  159.     
  160.     tst.l    d4
  161.     bne.s    Cont_Play
  162.     moveq.l    #1,d4
  163.  
  164. Cont_Play    move.w    d4,ioa_Cycles(a1)
  165.     move.w    #CMD_WRITE,IO_COMMAND(a1)
  166.  
  167.     move.l    d3,d7
  168.     andi.l    #$F,d7
  169.     move.l    d7,IO_UNIT(a1)
  170.  
  171.     BEGINIO
  172.  
  173.     btst.l    #5,d3
  174.     beq.s    Exit_Play
  175.  
  176.     move.l    4.w,a6
  177.     lea    AuReq,a1
  178.     jsr    _LVOWaitIO(a6)
  179.  
  180. Exit_Play:    
  181.     rts    
  182.  
  183.     
  184. DeAllocAudio:    lea    AuReq,a1
  185.     move.l    AuUnit,IO_UNIT(a1)
  186.     move.w    #ADCMD_FREE,IO_COMMAND(a1)
  187.     move.l    4.w,a6
  188.     jsr    _LVODoIO(a6)
  189.  
  190. DeAllocLoop:    move.l    _AuReplyPort,a0
  191.     move.l    4.w,a6
  192.     jsr    _LVOGetMsg(a6)
  193.     tst.l    d0
  194.     bne.s    DeAllocLoop
  195.  
  196.     move.l    _AuReplyPort,a0
  197.     move.l    4.w,a6
  198.     jsr    _LVODeleteMsgPort(a6)
  199.  
  200.     move.l    #AuReq,a1
  201.     move.l    4.w,a6
  202.     jsr    _LVOCloseDevice(a6)
  203.  
  204.     rts
  205.  
  206. AuDevice    dc.b    'audio.device',0
  207.  
  208. AuReq    ds.l    ioa_SIZEOF
  209.  
  210. _AuReplyPort    dc.l    0
  211.  
  212. AuChannels    dc.b    0
  213.  
  214. AuUnit    dc.l    0
  215.  
  216.  
  217. End_SimpleAudio
  218.